package service

import (
	"context"
	"go.uber.org/zap"
	"mall-portalv2/global"
	"mall-portalv2/internal/model"
)

func (s *Service) UpdateOmsOrderReturnApply(ctx context.Context, id int64, updates map[string]interface{}) error {
	if err := s.dao.UpdateOmsOrderReturnApply(ctx, id, updates); err != nil {
		return err
	}
	return nil
}

func (s *Service) QueryOmsOrderReturnApplyCount(ctx context.Context, Uid int64) (int64, error) {
	result, err := s.dao.QueryOmsOrderReturnApplyCount(ctx, Uid)
	if err != nil {
		return result, err
	}
	return result, nil
}

func (s *Service) QueryOmsOrderReturnApplyWhereID(ctx context.Context, id int64) (model.OmsOrderReturnApply, error) {
	result, err := s.dao.QueryOmsOrderReturnApplyWhereID(ctx, id)
	if err != nil {
		return result, err
	}
	global.Log.Info("打印一下查询的结果", zap.Any("data", result))
	return result, nil
}

func (s *Service) QueryViewOmsOrderReturnApplyList(ctx context.Context, memberId int64, pageNum, pageSize int) ([]model.ViewOmsOrderReturnApply, error) {

	var (
		result []model.ViewOmsOrderReturnApply
		err    error
		limit  = pageSize
		offset = (pageNum - 1) * pageSize
	)
	result, err = s.dao.QueryViewOmsOrderReturnApplyList(ctx, memberId, limit, offset)
	if err != nil {
		return []model.ViewOmsOrderReturnApply{}, err
	}
	return result, err
}

func (s *Service) QueryViewOmsOrderReturnApplyListCount(ctx context.Context, memberId int64) (int64, error) {
	var (
		result int64
		err    error
	)
	result, err = s.dao.QueryViewOmsOrderReturnApplyListCount(ctx, memberId)
	if err != nil {
		return 0, err
	}
	return result, err
}

func (s *Service) UpdateOmsOrderReturnApplyWhereOrderId(ctx context.Context, Order int64, updates map[string]interface{}) error {
	if err := s.dao.UpdateOmsOrderReturnApplyWhereOrderId(ctx, Order, updates); err != nil {
		return err
	}
	return nil
}
